<?php
namespace Admin\Controller;
use Think\Controller;
class WishManageController extends CommonController {
    public function index(){
       $sname=I('get.name','');
       $sop=I('get.sop',1);
       $wish=M('notes');
       $p=I('get.p',1);//从地址栏获取当前页
       //$wishda=$wish->page($p.',5')->select(); //分页第一个修改处
       //查询记录数
       if ($sop==1)
       {
           $wishda=$wish->where("name like '%$sname%' ")->page($p.',10')->select();
           $count=$wish->where("name like '%$sname%' ")->count();
       }
       else 
       {
           $wishda=$wish->where("name like '%$sname%' ")->page($p.',10')->select();
           $count=$wish->where("name like '%$sname%' ")->count();
       }
       //实例化分页类，传入总记录数和每页显示记录数
       $PAGE=new \Think\Page($count,10);
       //自动生成分页链接
       $PAGE->setConfig('header','共有%TOTAL_PAGE%页，当前是%NOW_PAGE%页<br/>');
       $PAGE->setConfig('first','首页');
       $PAGE->setConfig('last','尾页');
       $PAGE->setConfig('prev','上一页');
       $PAGE->setConfig('next','下一页');
       $PAGE->setConfig('theme','%HEADER%  %FIRST%  %UP_PAGE%  %DOWN_PAGE%  %END%');
       $show=$PAGE->show();
       $this->assign('wish',$wishda);
       $this->assign("page",$show);//视图里使用page显示分页链接
       $this->assign('sname',$sname);
       $this->display();
       
    }
    
    public function del(){
        $id=I('get.id',0);
	
       $model=M('notes'); 	     
	$rs=$model->delete($id);
	if ($rs)
	   { 
          $this->success('删除成功', U('Admin/WishManage/index'));  
	   }
	   else
	   { 
         $this->error('删除失败');
	   }
    }
    
}